import exp from "constants"
import {
	request,
	baseUrl
} from "../request.js"

//域名 端口号
//var baseUrl = 'https://wzxlovemzy.com:6001/user'

/**
 * 1，创建群聊
 * @param {Object} reqData
 */
export function createGroup(reqData) {
	return request({
		url: baseUrl + '/group/createGroup',
		method: 'POST',
		data: {
			createId: uni.getStorageSync('userId'),
			createName: uni.getStorageSync('nickname'),
			createHead: uni.getStorageSync('head'),
			typeName: reqData.typeName,
			userIds: reqData.userIds,
			groupName: reqData.groupName,
			groupHead: reqData.groupHead
		}
	})
}

/**
 * 2，获取群聊信息
 * @param {Object} gid
 */
export function getGroupInfo(gid) {
	return request({
		url: baseUrl + '/group/getGroupInfo?gid=' + gid,
		method: 'GET'
	})
}

/**
 * 3，添加用户到群聊
 * @param {Object} item
 */
export function addGroup(item) {
	return request({
		url: baseUrl + '/group/addGroup',
		method: 'POST',
		data: {
			addId: item.addId,
			createTime: item.createTime,
			groupId: item.groupId,
			id: item.id,
			message: item.message,
			receiverId: item.receiverId,
			senderHead: item.senderHead,
			senderId: item.senderId,
			senderName: item.senderName,
			state: item.state,
			sysType: item.sysType
		}
	})
}


/**
 * 4，获取群聊消息
 * @param {Object} item
 */
export function getMsgByGroup(page, size, gid) {
	return request({
		url: baseUrl + '/group/getMsgByGroup?page=' + page + '&size=' + size + '&gid=' + gid,
		method: 'GET'

	})
}

/**
 * 5，获取群聊可以拉取的用户
 * @param {Object} userId
 * @param {Object} gid
 */
export function getGroupFriend(userId, gid) {
	return request({
		url: baseUrl + '/group/getGroupFriend?userId=' + userId + '&gid=' + gid,
		method: 'GET'

	})
}

/**
 * 6，删除群组
 * @param {Object} gid 群聊id
 * @param {Object} userId 用户id
 */
export function deleteGroup(gid, userId) {
	return request({
		url: baseUrl + '/group/deleteGroupById?groupId=' + gid + '&userId=' + userId,
		method: 'GET'

	})
}

/**
 * 7，查询群聊的昵称，头像，备注
 * @param {Object} gid 群聊id
 * @param {Object} userId 用户id
 */
export function queryGroupByHeadInfo(gid, userId) {
	return request({
		url: baseUrl + '/group/queryGroupByHeadInfo?groupId=' + gid + '&userId=' + userId,
		method: 'GET'

	})
}

/**
 * 8，修改群聊的昵称，头像，备注
 * @param {Object} groupHeadInfo
 */
export function updateGroupByHeadInfo(groupHeadInfo) {
	return request({
		url: baseUrl + '/group/updateGroupByHeadInfo',
		method: 'POST',
		data: {
			userId: groupHeadInfo.userId,
			groupId: groupHeadInfo.groupId,
			groupName: groupHeadInfo.groupName,
			groupHead: groupHeadInfo.groupHead,
			describe: groupHeadInfo.describe,
			identity: groupHeadInfo.identity
		}

	})
}

/**
 * 9，查询群聊成员
 * @param {Object} gid
 */
export function queryGroupUsers(groupId, searchName, isAdmin, excludingOneself) {
	return request({
		url: baseUrl + '/group/queryGroupUsers',
		method: 'POST',
		data: {
			groupId,
			searchName,
			isAdmin,
			excludingOneself: excludingOneself || '',
			userId: uni.getStorageSync('userId')
		}
	})
}

//10，获取群聊基本信息
export function queryGroupInfo(groupId) {
	return request({
		url: baseUrl + '/group/queryGroupInfo?groupId=' + groupId,
		method: 'GET'
	})
}

//11，更改群聊状态
/**
 * @param {Object} groupId 群聊id
 * @param {Object} estoppel 禁言状态
 * @param {Object} protect 保护模式
 */
export function changeGroupState(groupId, estoppel, protect, inviteType) {
	return request({
		url: baseUrl + '/group/changeGroupState',
		method: 'POST',
		data: {
			groupId,
			estoppel,
			protect,
			inviteType: inviteType || ''
		}
	})
}

//12，更改用户身份
/**
 * @param {Object} users
 * @param {Object} identity
 * @param {Object} groupId
 */
export function changeUsersAdmin(users, identity, groupId) {
	return request({
		url: baseUrl + '/group/changeUsersAdmin',
		method: 'POST',
		data: {
			users,
			identity,
			groupId
		}
	})
}

/**
 * 13，批量删除群聊用户
 * @param {Object} gid
 * @param {Object} userIds
 */
export function deleteGroupByIds(groupId, userIds) {
	return request({
		url: baseUrl + '/group/deleteGroupByIds',
		method: 'POST',
		data: {
			groupId,
			userIds
		}

	})
}

/**
 * 14，根据群聊id解散
 * @param {Object} groupId
 */
export function dissolutionGroup(groupId) {
	return request({
		url: baseUrl + '/group/dissolutionGroup?groupId=' + groupId,
		method: 'GET'
	})
}